Add M nearest-neighbour Chatterjee correlation (#990)#1414
Merged
Conversation
mborland
approved these changes
Jul 2, 2026
mborland
left a comment
Member
There was a problem hiding this comment.
I've approved the workflow. This all looks good to me! @NAThompson if you have time could you give this a quick look?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1414 +/- ##
===========================================
+ Coverage 95.39% 95.40% +0.01%
===========================================
Files 826 827 +1
Lines 68919 69062 +143
===========================================
+ Hits 65747 65891 +144
+ Misses 3172 3171 -1
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Member
|
macOS failure has already been fixed on develop. Merging. Thank you for this contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the revised (M nearest-neighbour) Chatterjee rank correlation of
Lin & Han (2021), addressing #990. Adds a new function
chatterjee_correlation_mnn(u, v, M)alongside the existingchatterjee_correlation, with the same C++11 and C++17 overload structure.The original coefficient has a detection boundary of n^(-1/4) for independence
testing, well short of the parametric n^(-1/2) rate. By using the M right
nearest neighbours of each point (rather than the single right neighbour) and
letting M grow with n, the revised statistic consistently estimates the same
dependence measure while approaching near-parametric efficiency. See Lin & Han,
On boosting the power of Chatterjee's rank correlation, Biometrika 110(2)
(2023) 283–299, arXiv:2108.06828.
Design notes
Separate function rather than an extended signature. The M-NN statistic
uses
min(R_i, R_j)and a different normalisation, so even at M = 1 it is notidentical to
chatterjee_correlation. A distinct function avoids silentlychanging existing results and keeps the statistical intent explicit.
Mis a required argument with no default.Rank base. The internal
rank()returns 0-based ranks; the paper'sformula uses 1-based ranks. The offset cancels in the existing M = 1 statistic
(which uses
|R_i - R_{i+1}|) but not undermin(.,.), so it is appliedexplicitly. This is noted in a comment where it matters.
Complexity. O(n log n + nM). Near-linear for small M; tends to O(n²) as
M → n.
Parallel path. The outer index loop is partitioned across threads into
disjoint ranges, each reading the shared rank vector read-only (indices up to
i + M may fall in a neighbouring range; there are no writes). This differs
from the M = 1 parallel path, which splits the data array for the
difference-based transform.
Ties / degenerate input. Like
chatterjee_correlation, the functionassumes distinct Y (continuous data). A constant Y returns a quiet NaN; this
is detected on the input directly, since
rank()collapses tied values.Choice of M. The asymptotic null variance is minimised at M ~ sqrt(n); the
choice is documented but left to the caller.
Tests
Added to
test_chatterjee_correlation.cpp, coveringfloat,double, andlong double:and strictly decreasing dependence), which require no external reference.
and Y.
The sequential path was verified locally under
b2withcxxstd=14andcxxstd=17(clang, arm64).